package net.hn.hnms.biz.plan.company.service.impl;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.plan.company.service.CompanyService;
import net.hn.hnms.biz.plan.domain.DimMiningFace;
import net.hn.hnms.biz.plan.domain.PlanMining;
import net.hn.hnms.biz.plan.enums.DataType;
import net.hn.hnms.biz.plan.enums.MineInfo;
import net.hn.hnms.biz.plan.mapper.*;
import net.hn.hnms.biz.plan.request.*;
import net.hn.hnms.biz.plan.service.impl.BaseService;
import net.hn.hnms.biz.plan.vo.*;
import net.hn.hnms.sys.common.core.constant.Constants;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.utils.DateUtils;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.*;

import static net.hn.hnms.sys.common.core.utils.DateUtils.YYYY_MM_DD;

@Service
public class CompanyServiceImpl  extends BaseService<PlanMining, PlanMiningVO> implements CompanyService {


    @Autowired
    private PlanMiningMapper planMiningMapper;

    @Autowired
    private PlanDrivageMapper planDrivageMapper;

    @Autowired
    private PlanWashingMapper planWashingMapper;

    @Autowired
    private PlanOtherMapper planOtherMapper;

    @Autowired
    private DimDrivageFaceMapper dimDrivageFaceMapper;

    @Autowired
    private DimMiningFaceMapper dimMiningFaceMapper;

    @Autowired
    private PlanOutputMapper planOutputMapper;

    @Autowired
    private ExecutionFootageOutputMapper footageOutputMapper;

    @Autowired
    private ExecutionOtherMapper otherMapper;

    @Autowired
    private ExecutionWashingMapper washingMapper;

    @Autowired
    private ExecutionCostMapper costMapper;

    @Autowired
    private StatisticMapper statisticMapper;


    @Override
    public List<PlanMiningVO> selectTotalByMineCode(Map<String, String> map) {
        if(map != null){
            List<PlanMiningVO> planMiningVOS = new ArrayList<>();
            for(String key : map.keySet()){
                String value = map.get(key);
                //根据矿编码汇总数据
                PlanMiningVO planMiningVO = planMiningMapper.selectTotalByMineCode(key);
                if(planMiningVO==null){
                    continue;
                }
                planMiningVO.setMineName(value);
                planMiningVO.setMineCode(key);
                planMiningVOS.add(planMiningVO);
            }
            return planMiningVOS;
        }

        return null;
    }

    @Override
    public List<PlanMiningVO> selectTotalByMineCode(PlanMiningReq planMining) {
        List<PlanMiningVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            //先根据公司编码拿公司下所属得矿，拿到矿编码  再查询矿
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
            //拿到两个矿编码,根据矿编码汇总数据
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
            //如果名字不为空则先查询部门表 根据名字模糊查询部门表，如果结果为空，则返回空，不为空，则根据查询出来的部门信息  查询汇总数据
            //如果 minecode 不为空 则根据 minecode 直接汇总
            //如果两个都不为空  先根据minecode 汇总，如果为空，则返回空，不为空则根据minecode 汇总，以minecode 为优先级
        }
//        map.clear();
        return selectTotalByCompanyCodeOrMineCodeOrName(map);
    }
    public List<PlanMiningVO> selectTotalByCompanyCodeOrMineCodeOrName(Map<String, String> map){
        List<PlanMiningVO> planMiningVOS = new ArrayList<>();
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            PlanMiningVO planMiningVO = planMiningMapper.selectTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            if(planMiningVO.getTotalPlan().equals("0")){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }
    @Override
    public List<PlanDrivageVO> selectDrivageTotalByMineCode(PlanDrivageReq planMining) {
        List<PlanDrivageVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            PlanDrivageVO planMiningVO = planDrivageMapper.selectDrivageTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<PlanWashingVO> selectWashingTotalByMineCode(PlanWashingReq planMining) {
        List<PlanWashingVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            PlanWashingVO planMiningVO = planWashingMapper.selectWashingTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<PlanOtherVO> selectOtherTotalByMineCode(PlanOtherReq planMining) {
        List<PlanOtherVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            PlanOtherVO planMiningVO = planOtherMapper.selectOtherTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<DimMiningFaceVO> selectDimMiningFaceTotalByMineCode(DimMiningFaceReq planMining) {
        List<DimMiningFaceVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        DynamicDataSourceContextHolder.push("slave");
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            DimMiningFaceVO planMiningVO = dimMiningFaceMapper.selectDimMiningFaceTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        DynamicDataSourceContextHolder.clear();
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<DimDrivageFaceVO> selectDimDrivageFaceTotalByMineCode(DimDrivageFaceReq planMining) {
        List<DimDrivageFaceVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        DynamicDataSourceContextHolder.push("slave");
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            DimDrivageFaceVO planMiningVO = dimDrivageFaceMapper.selectDimMiningFaceTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        DynamicDataSourceContextHolder.clear();
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<PlanOutputVO> selectPlanOutputTotalByMineCode(PlanOutputReq planMining) {
        List<PlanOutputVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
//        DynamicDataSourceContextHolder.push("slave");
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            PlanOutputVO planMiningVO = planOutputMapper.selectPlanOutPutTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
//        DynamicDataSourceContextHolder.clear();
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<ExecutionFootageOutputVO> selectFootageOutputTotalByMineCode(ExecutionFootageOutputReq planMining) {
        List<ExecutionFootageOutputVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
//        DynamicDataSourceContextHolder.push("slave");
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            ExecutionFootageOutputVO planMiningVO = footageOutputMapper.selectPlanOutPutTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
//        DynamicDataSourceContextHolder.clear();
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<ExecutionOtherVO> selectExecutionOtherTotalByMineCode(ExecutionOtherReq planMining) {
        List<ExecutionOtherVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
//        DynamicDataSourceContextHolder.push("slave");
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            ExecutionOtherVO planMiningVO = otherMapper.selectExecutionOtherTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
//        DynamicDataSourceContextHolder.clear();
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<ExecutionWashingVO> selectExecutionWashingTotalByMineCode(ExecutionWashingReq planMining) {
        List<ExecutionWashingVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            ExecutionWashingVO planMiningVO = washingMapper.selectExecutionWashingTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<ExecutionCostVO> selectExecutionCostTotalByMineCode(ExecutionCostReq planMining) {
        List<ExecutionCostVO> planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            ExecutionCostVO planMiningVO = costMapper.selectExecutionCostTotalByMineCode(key);
            if(planMiningVO==null){
                continue;
            }
            planMiningVO.setMineName(value);
            planMiningVO.setMineCode(key);
            planMiningVOS.add(planMiningVO);
        }
        map.clear();
        return planMiningVOS;
    }

    @Override
    public List<MiningContinuationVo> selectMiningContinuationByMineCode(PlanMiningReq planMining) {
        List<MiningContinuationVo>  planMiningVOS = new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        DynamicDataSourceContextHolder.push("slave");
        List<DimMiningFaceVO> list =new ArrayList<>();
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            list  = dimMiningFaceMapper.selectDimMiningFaceByMineCode(key);
            if(list!=null){
                for (DimMiningFaceVO dim :list){
//                    dim.setMineCode(key);
                    dim.setMineName(value);
                }
            }

        }

        //先查询所有工作面信息
        DynamicDataSourceContextHolder.clear();

        LocalDate localDate = LocalDate.now();
        System.out.println("localDate = " + localDate);
        //当月最后一天
        LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("lastDay = " + lastDay);
        //当月第一天
        LocalDate firstDay = localDate.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("firstDay = " + firstDay);

        WeekFields weekFields= WeekFields.ISO;
        LocalDate now = LocalDate.now();
        LocalDate mondayDate = now.with(weekFields.dayOfWeek(), 1L);//本周第一天
        LocalDate sundayDate = now.with(weekFields.dayOfWeek(), 7L);//本周最后一天
        System.out.println(mondayDate);
        System.out.println(sundayDate);
        boolean before = mondayDate.isBefore(firstDay);//本周第一天如果是本月第一天之前
        if(before){
            //获取上个月的最后一天
            LocalDate date = LocalDate.now();
            date = date.minusMonths(1);
            LocalDate with = date.with(TemporalAdjusters.lastDayOfMonth());
            System.out.println("上个月的最后一天 = " +with);
            Period period = Period.between( mondayDate,with);
            int days = period.getDays()+1;//相差多少天
            System.out.println(days+"天");
            Integer upDays = date.lengthOfMonth();
            System.out.println("上个月"+date.lengthOfMonth()+"天");
            LocalDate lastDay1 = date.with(TemporalAdjusters.lastDayOfMonth());
            System.out.println("lastDay = " + lastDay1);
            //当月第一天
            LocalDate firstDay1 = date.with(TemporalAdjusters.firstDayOfMonth());
            System.out.println("firstDay = " + firstDay1);
            //在计算本月本周有多少天
            Period period1 = Period.between(firstDay ,sundayDate);
            int days1 = period1.getDays()+1;//相差多少天
            System.out.println(days1+"天");//相差多少天
            //查询上月的总计划/天数*本周上月所占天数+（本月总计划/本月天数*本周本月天数）
            System.out.println("这个月"+firstDay.lengthOfMonth()+"天");
            int benyuedays = firstDay.lengthOfMonth();
            for (DimMiningFaceVO s : list){
                //查询上月的总计划
                PlanMiningVO shangyue = planMiningMapper.selectMiningPlanFootageByMineCode(s.getMiningFaceId(),String.valueOf(firstDay1),String.valueOf(lastDay1));
                PlanMiningVO benyue = planMiningMapper.selectMiningPlanFootageByMineCode(s.getMiningFaceId(),String.valueOf(firstDay1),String.valueOf(lastDay1));
                PlanMiningVO totalbenyue = planMiningMapper.selectMiningPlanFootageByMineCode(s.getMiningFaceId(),String.valueOf(firstDay),String.valueOf(lastDay));
                BigDecimal shangyuejihua = new BigDecimal("0");
                BigDecimal shangyueMingPlanFootage = shangyue.getMiningPlanFootage()==null?new BigDecimal("0"):shangyue.getMiningPlanFootage();
                shangyuejihua .add( shangyue.getMiningPlanFootage().divide(new BigDecimal(upDays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days)));
                BigDecimal benyuejihua = new BigDecimal("0");
                BigDecimal benyueFootage = new BigDecimal("0");
                if(benyue!=null){
                    benyueFootage = benyueFootage.add(benyue.getMiningPlanFootage());
                }
                benyuejihua .add( benyueFootage.divide(new BigDecimal(benyuedays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days1)));
                BigDecimal heji = new BigDecimal("0");
                heji.add(shangyuejihua.add(benyuejihua));
//                //再查询进尺产量执行推进度
                ExecutionFootageOutputVO outputVO = footageOutputMapper.selectPlanOutPutByFaceIdAndDate(s.getMiningFaceId(), mondayDate.toString(), sundayDate.toString());
                ExecutionFootageOutputVO leiji = footageOutputMapper.selectPlanOutPutByFaceId(s.getMiningFaceId(), mondayDate.toString(), sundayDate.toString());
                MiningContinuationVo vo = new MiningContinuationVo();
                vo.setMineName(s.getMineName());
                vo.setMiningFaceName(s.getMiningFaceName());
                vo.setStatus(s.getStatus());
                vo.setWeeksPlan(heji);
                BigDecimal  footage  = new BigDecimal("0");
                if(outputVO!=null){
                    footage = footage.add(outputVO.getFootage());
                }
                vo.setAdvanceWeek(footage.toString());//本周推进度
                BigDecimal  leijifootage  = new BigDecimal("0");
                if(leiji!=null){
                    leijifootage = leijifootage.add(leiji.getFootage());
                }
                vo.setCumulativeRecovery(leijifootage.toString());//累计回采长度
                vo.setRemainingLength(String.valueOf(s.getMiningFaceLength().subtract(leiji.getFootage())));//剩余长度
                vo.setParameter(s.getMiningFaceName()+","+s.getMiningFaceHigh()+","+s.getMiningFaceAngle()+","+s.getMiningFaceAngle());
                vo.setEstimateEndDate(DateUtils.parseDateToStr("yyyy-mm-dd",s.getEstimateEndDate()));
                //根据id 查询工作面
                if(s.getRelocation()!=null&&s.getRelocation().equals("1")){
                    vo.setRelocation("回撤");
                }else{
                    DynamicDataSourceContextHolder.push("slave");
                    DimMiningFace dimMiningFace = dimMiningFaceMapper.selectById(s.getRelocation());
                    DynamicDataSourceContextHolder.clear();

                    vo.setRelocation(s.getRelocation()!=null?dimMiningFace.getMiningFaceName():null);
                }
                BigDecimal divide = new BigDecimal("0");
                divide.add(s.getMiningFaceLength().divide(new BigDecimal("4"),2, BigDecimal.ROUND_HALF_UP));
                Integer week = getWeekOfMonth(new Date());
                Integer weeks= week;
                if(outputVO.getFootage().compareTo(divide)==-1){


                    BigDecimal divide1 = totalbenyue.getMiningPlanFootage().divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    vo.setWarning("回采进度慢，建议本周回采"+divide1);
                }else{
                    BigDecimal divide1 = totalbenyue.getMiningPlanFootage().divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    vo.setWarning("回采进度快，建议本周回采"+divide1);
                }
                vo.setMineCode(s.getMineCode());
                planMiningVOS.add(vo);
            }

        }else{
            //本月总计划/本月天数*本周本月天数=本周计划
            Period period1 = Period.between(mondayDate ,sundayDate);
            int days1 = period1.getDays()+1;//相差多少天
            System.out.println(days1+"天");//相差多少天
            int benyuedays = firstDay.lengthOfMonth();
            for (DimMiningFaceVO s : list){
                PlanMiningVO benyue = planMiningMapper.selectMiningPlanFootageByMineCode(s.getMiningFaceId(),String.valueOf(firstDay),String.valueOf(lastDay));
                BigDecimal benyuejihua = new BigDecimal("0");
                BigDecimal benyueMiningPlanFootage = new BigDecimal("0");
                if(benyue!=null){
                    benyueMiningPlanFootage = benyueMiningPlanFootage.add(benyue.getMiningPlanFootage());
                }

                benyuejihua .add(benyueMiningPlanFootage.compareTo(new BigDecimal("0"))==0?new BigDecimal("0"): benyueMiningPlanFootage.divide(new BigDecimal(benyuedays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days1)));
                //本周推进度=本周第一天到本周最后一天累计回采长度
                ExecutionFootageOutputVO outputVO = footageOutputMapper.selectPlanOutPutByFaceIdAndDate(s.getMiningFaceId(), mondayDate.toString(), sundayDate.toString());
                //累计回采长度是这个工作面总共回采的长度
                ExecutionFootageOutputVO leiji = footageOutputMapper.selectPlanOutPutByFaceId(s.getMiningFaceId(), mondayDate.toString(), sundayDate.toString());
                //剩余长度= 这个工作面总长度-累计回采长度
                BigDecimal heji = new BigDecimal("0");
                heji.add(benyuejihua);
                MiningContinuationVo vo = new MiningContinuationVo();
                vo.setMineName(s.getMineName());
                vo.setMiningFaceName(s.getMiningFaceName());
                vo.setStatus(s.getStatus());
                vo.setWeeksPlan(heji);
                BigDecimal  footage  = new BigDecimal("0");
                if(outputVO!=null){
                    footage = footage.add(outputVO.getFootage());
                }
                vo.setAdvanceWeek(footage+"");//本周推进度
                BigDecimal  leijifootage  = new BigDecimal("0");
                if(leiji!=null){
                    leijifootage = leijifootage.add(leiji.getFootage());
                }
                vo.setCumulativeRecovery(leijifootage+"");//累计回采长度
                vo.setRemainingLength(String.valueOf(s.getMiningFaceLength().subtract(leijifootage)));//剩余长度
                vo.setParameter(s.getMiningFaceName()+","+s.getMiningFaceHigh()+","+s.getMiningFaceAngle()+","+s.getMiningFaceAngle());
                vo.setEstimateEndDate(DateUtils.parseDateToStr(YYYY_MM_DD,s.getEstimateEndDate()));
                //根据id 查询工作面


                if(s.getRelocation()!=null&&s.getRelocation().equals("1")){
                    vo.setRelocation("回撤");
                }else{
                    DynamicDataSourceContextHolder.push("slave");
                    DimMiningFace dimMiningFace = dimMiningFaceMapper.selectById(s.getRelocation());
                    DynamicDataSourceContextHolder.clear();

                    vo.setRelocation(s.getRelocation()!=null&&!s.getRelocation().equals("")?dimMiningFace.getMiningFaceName():null);
                }
                BigDecimal divide = new BigDecimal("0");
                divide.add(s.getMiningFaceLength().divide(new BigDecimal("4"),2, BigDecimal.ROUND_HALF_UP));
                Integer week = getWeekOfMonth(new Date());
                Integer weeks= week;
                if(footage.compareTo(divide)==-1){
                    BigDecimal divide1 = benyueMiningPlanFootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    vo.setWarning("回采进度慢，建议本周回采"+divide1);
                }else{
                    BigDecimal divide1 = benyueMiningPlanFootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    vo.setWarning("回采进度快，建议本周回采"+divide1);
                }
                vo.setMineCode(s.getMineCode());
                planMiningVOS.add(vo);
            }
        }
        return planMiningVOS;
    }

    @Override
    public ResponsePage<DimDrivageFaceVO> selectDrivageContinuationByMineCode(PageQuery pageQuery, PlanDrivageReq planMining) {
        List<MiningContinuationVo>  list1= new ArrayList<>();
        Map<String, String> map = new HashMap<>();
        if(planMining.getCompanyCode()!=null&&(planMining.getMineCode()==null||planMining.getMineCode()=="")&&(planMining.getMineName()==null||planMining.getMineName()=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(planMining.getCompanyCode());
        }else{
            map = MineInfo.getNameByMineCodeAndName(planMining.getCompanyCode(),planMining.getCompanyName(),planMining.getMineCode(),planMining.getMineName());
        }
        DynamicDataSourceContextHolder.push("slave");
        Page<DimDrivageFaceVO> page = new Page<>();
        for(String key : map.keySet()){
            String value = map.get(key);
            //根据矿编码汇总数据
            page  = dimDrivageFaceMapper.selectDimDrivageFaceByMineCode(pageQuery.build(),key);
            if(page!=null){
                for (DimDrivageFaceVO dim :page.getRecords()){
//                    dim.setMineCode(key);
                    dim.setMineName(value);
                }
            }

        }

        //先查询所有工作面信息
        DynamicDataSourceContextHolder.clear();
        LocalDate localDate = LocalDate.now();
        System.out.println("localDate = " + localDate);
        //当月最后一天
        LocalDate lastDay = localDate.with(TemporalAdjusters.lastDayOfMonth());
        System.out.println("lastDay = " + lastDay);
        //当月第一天
        LocalDate firstDay = localDate.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("firstDay = " + firstDay);

        WeekFields weekFields= WeekFields.ISO;
        LocalDate now = LocalDate.now();
        LocalDate mondayDate = now.with(weekFields.dayOfWeek(), 1L);//本周第一天
        LocalDate sundayDate = now.with(weekFields.dayOfWeek(), 7L);//本周最后一天
        System.out.println(mondayDate);
        System.out.println(sundayDate);
        boolean before = mondayDate.isBefore(firstDay);//本周第一天如果是本月第一天之前
        if(before){
            //获取上个月的最后一天
            LocalDate date = LocalDate.now();
            date = date.minusMonths(1);
            LocalDate with = date.with(TemporalAdjusters.lastDayOfMonth());
            System.out.println("上个月的最后一天 = " +with);
            Period period = Period.between( mondayDate,with);
            int days = period.getDays()+1;//相差多少天
            System.out.println(days+"天");
            Integer upDays = date.lengthOfMonth();
            System.out.println("上个月"+date.lengthOfMonth()+"天");
            LocalDate lastDay1 = date.with(TemporalAdjusters.lastDayOfMonth());
            System.out.println("lastDay = " + lastDay1);
            //当月第一天
            LocalDate firstDay1 = date.with(TemporalAdjusters.firstDayOfMonth());
            System.out.println("firstDay = " + firstDay1);
            //在计算本月本周有多少天
            Period period1 = Period.between(firstDay ,sundayDate);
            int days1 = period1.getDays()+1;//相差多少天
            System.out.println(days1+"天");//相差多少天
            //查询上月的总计划/天数*本周上月所占天数+（本月总计划/本月天数*本周本月天数）
            System.out.println("这个月"+firstDay.lengthOfMonth()+"天");
            int benyuedays = firstDay.lengthOfMonth();
            for (DimDrivageFaceVO s : page.getRecords()){
                //查询上月的总计划
                PlanDrivageVO shangyue = planDrivageMapper.selectDrivagePlanFootageByMineCode(s.getDrivageFaceId(),String.valueOf(firstDay1),String.valueOf(lastDay1));
                PlanDrivageVO benyue = planDrivageMapper.selectDrivagePlanFootageByMineCode(s.getDrivageFaceId(),String.valueOf(firstDay1),String.valueOf(lastDay1));
                PlanDrivageVO totalbenyue = planDrivageMapper.selectDrivagePlanFootageByMineCode(s.getDrivageFaceId(),String.valueOf(firstDay),String.valueOf(lastDay));
                BigDecimal shangyuejihua = new BigDecimal("0");
                BigDecimal shangyuefootage = new BigDecimal("0");
                BigDecimal benyuefootage = new BigDecimal("0");
                BigDecimal totalbenyuefootage = new BigDecimal("0");
                if(shangyue==null){
                    shangyuefootage.add(new BigDecimal("0"));
                }else{
                    shangyuefootage.add(shangyue.getDrivagePlanFootage());
                }
                if(benyue==null){
                    benyuefootage.add(new BigDecimal("0"));
                }else{
                    benyuefootage.add(benyue.getDrivagePlanFootage());
                }
                if(totalbenyue==null){
                    totalbenyuefootage.add(new BigDecimal("0"));
                }else{
                    totalbenyuefootage.add(totalbenyue.getDrivagePlanFootage());
                }
                BigDecimal shangyueMingPlanFootage = shangyuefootage==null?new BigDecimal("0"):shangyuefootage;
                shangyuejihua .add( shangyuefootage.divide(new BigDecimal(upDays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days)));
                BigDecimal benyuejihua = new BigDecimal("0");
                benyuejihua .add(benyuefootage.divide(new BigDecimal(benyuedays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days1)));
                BigDecimal heji = new BigDecimal("0");
                heji.add(shangyuejihua.add(benyuejihua));

                //再查询进尺产量执行推进度
                ExecutionFootageOutputVO outputVO = footageOutputMapper.selectPlanOutPutByFaceIdAndDate(s.getDrivageFaceId(), mondayDate.toString(), sundayDate.toString());
                BigDecimal outputvo = new BigDecimal("0");
                if(outputVO==null||outputVO.getFootage()==null){
                    outputvo.add(new BigDecimal("0"));
                }else{
                    outputvo.add(outputVO.getFootage());
                }
                ExecutionFootageOutputVO leiji = footageOutputMapper.selectPlanOutPutByFaceId(s.getDrivageFaceId(), mondayDate.toString(), sundayDate.toString());
                BigDecimal leijifootage = new BigDecimal("0");
                if(leiji==null||leiji.getFootage()==null){
                    leijifootage.add(new BigDecimal("0"));
                }else{
                    leijifootage.add(leiji.getFootage());
                }
                s.setMineName(s.getMineName());
                s.setDrivageFaceName(s.getDrivageFaceName());
                s.setStatus(s.getStatus());
                s.setWeeksPlan(heji);
                s.setAdvanceWeek(outputvo.toString());//本周推进度
                s.setCumulativeRecovery(leijifootage.toString());//累计回采长度
                s.setRemainingLength(String.valueOf(s.getDrivageFaceLength().subtract(leijifootage)));//剩余长度
                s.setCoalRockType(null);//煤岩类型
                s.setRemarks(null);//备注
                s.setDrivingForm(null);//掘进形式
                BigDecimal divide = new BigDecimal("0");
                divide.add(s.getDrivageFaceLength().divide(new BigDecimal("4"),2, BigDecimal.ROUND_HALF_UP));
                Integer week = getWeekOfMonth(new Date());
                Integer weeks= week;
                if(outputvo.compareTo(divide)==-1){
                    BigDecimal divide1 = totalbenyuefootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    s.setWarning("回采进度慢，建议本周回采"+divide1);
                }else{
                    BigDecimal divide1 = totalbenyuefootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    s.setWarning("回采进度快，建议本周回采"+divide1);
                }
                s.setMineCode(s.getMineCode());

            }
        }else{
            //本月总计划/本月天数*本周本月天数=本周计划
            Period period1 = Period.between(mondayDate ,sundayDate);
            int days1 = period1.getDays()+1;//相差多少天
            System.out.println(days1+"天");//相差多少天
            int benyuedays = firstDay.lengthOfMonth();
            for (DimDrivageFaceVO s : page.getRecords()){
                PlanDrivageVO benyue = planDrivageMapper.selectDrivagePlanFootageByMineCode(s.getDrivageFaceId(),String.valueOf(firstDay),String.valueOf(lastDay));
                BigDecimal benyuejihua = new BigDecimal("0");
                BigDecimal benyuefootage = new BigDecimal("0");
                if(benyue==null){
                    benyuefootage.add(new BigDecimal("0"));
                }else{
                    benyuefootage.add(benyue.getDrivagePlanFootage());
                }
                benyuejihua .add( benyuefootage.divide(new BigDecimal(benyuedays), 0, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(days1)));
                //本周推进度=本周第一天到本周最后一天累计回采长度
                ExecutionFootageOutputVO outputVO = footageOutputMapper.selectPlanOutPutByFaceIdAndDate(s.getDrivageFaceId(), mondayDate.toString(), sundayDate.toString());
                //累计回采长度是这个工作面总共回采的长度
                ExecutionFootageOutputVO leiji = footageOutputMapper.selectPlanOutPutByFaceId(s.getDrivageFaceId(), mondayDate.toString(), sundayDate.toString());
                BigDecimal leijifootage = new BigDecimal("0");
                if(leiji==null||leiji.getFootage()==null){
                    leijifootage.add(new BigDecimal("0"));
                }else{
                    leijifootage.add(leiji.getFootage());
                }
                //剩余长度= 这个工作面总长度-累计回采长度
                BigDecimal heji = new BigDecimal("0");
                heji.add(benyuejihua);
                s.setMineName(s.getMineName());
                s.setDrivageFaceName(s.getDrivageFaceName());
                s.setStatus(s.getStatus());
                s.setWeeksPlan(heji);
                BigDecimal footage  = new BigDecimal("0");
                if(outputVO!=null){
                    footage = footage.add(outputVO.getFootage());
                }
                s.setAdvanceWeek(footage+"");//本周推进度
                s.setCumulativeRecovery(leijifootage.toString());//累计回采长度
                s.setRemainingLength(String.valueOf(s.getDrivageFaceLength().subtract(leijifootage)));//剩余长度
                s.setCoalRockType(null);//煤岩类型
                s.setRemarks(null);//备注
                s.setDrivingForm(null);//掘进形式
                BigDecimal divide = new BigDecimal("0");
                divide.add(s.getDrivageFaceLength().divide(new BigDecimal("4"),2, BigDecimal.ROUND_HALF_UP));
                Integer week = getWeekOfMonth(new Date());
                Integer weeks= week;
                if(footage.compareTo(divide)==-1){
                    BigDecimal divide1 = benyuefootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    s.setWarning("回采进度慢，建议本周回采"+divide1);
                }else{
                    BigDecimal divide1 = benyuefootage.divide(new BigDecimal(weeks.toString()),2, BigDecimal.ROUND_HALF_UP);
                    s.setWarning("回采进度快，建议本周回采"+divide1);
                }
                s.setMineCode(s.getMineCode());
            }
        }
        map.clear();
//        List<DimDrivageFaceVO> list = page.getRecords().stream().map(o -> convert(o,DimDrivageFaceVO.class)).collect(Collectors.toList());
        return new ResponsePage<>(page.getRecords(), page.getTotal());
    }

    @Override
    public Map<String, PlanStatisticVO> completeByMineCode(Integer month,String companyCode,String companyName, String mineCode) {
        Map<String, String> map = new HashMap<>();
        if(companyCode!=null&&!companyCode.equals("")&&(mineCode==null||mineCode=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(companyCode);
        }else{
            map = MineInfo.getNameByMineCodeAndName(companyCode,companyName,mineCode,null);
        }

        StringBuffer value = new StringBuffer();
        for(String key : map.keySet()){
            value.append(key).append(",");
            //根据矿编码汇总数据
        }
        String keywordStr = value.deleteCharAt(value.length() - 1).toString();//去掉最后一个逗号
        map.clear();
        //获得起始日期
        Date[] dateRange = DateUtils.getDateRange(null, month);

        PlanCompleteStatisticVO completeInfo = statisticMapper.planComplete(dateRange[0], dateRange[1],keywordStr);
        Map<String, PlanStatisticVO> result = new HashMap<>();
        result.put(DataType.DEVELOP.name(), createPlanComplete(DataType.DEVELOP, completeInfo.getPlanDevelopment(), completeInfo.getDevelopment()));
        result.put(DataType.DRIVAGE.name(), createPlanComplete(DataType.DRIVAGE, completeInfo.getPlanDrivage(), completeInfo.getDrivage()));
        result.put(DataType.MINING.name(), createPlanComplete(DataType.MINING, completeInfo.getPlanMining(), completeInfo.getMining()));
        result.put(DataType.OUTPUT.name(), createPlanComplete(DataType.OUTPUT, completeInfo.getPlanOutput().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING), completeInfo.getOutput().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING)));
        result.put(DataType.WASHING.name(), createPlanComplete(DataType.WASHING, completeInfo.getPlanWashing().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING), completeInfo.getWashing().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING)));
        return result;

    }

    @Override
    public Map<String, PlanStatisticVO> otherPlanByMineCode(Integer month, String companyCode,String companyName, String mineCode) {

        Map<String, String> map = new HashMap<>();
        if(companyCode!=null&&!companyCode.equals("")&&(mineCode==null||mineCode=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(companyCode);
        }else{
            map = MineInfo.getNameByMineCodeAndName(companyCode,companyName,mineCode,null);
        }

        StringBuffer value = new StringBuffer();
        for(String key : map.keySet()){
            value.append(key).append(",");
            //根据矿编码汇总数据
        }
        String keywordStr = value.deleteCharAt(value.length() - 1).toString();//去掉最后一个逗号
        map.clear();

        //获得起始日期
        Date[] dateRange = DateUtils.getDateRange(null, month);
        PlanOtherStatisticVO completeInfo = statisticMapper.planOther(dateRange[0], dateRange[1],keywordStr);
        Map<String, PlanStatisticVO> result = new HashMap<>();
        result.put(DataType.REPAIR.name(), createPlanComplete(DataType.REPAIR, completeInfo.getPlanRepair(), completeInfo.getRepair(), 0, RoundingMode.CEILING));
        result.put(DataType.GROUT.name(), createPlanComplete(DataType.GROUT, completeInfo.getPlanGrout(), completeInfo.getGrout(), 0, RoundingMode.CEILING));
        result.put(DataType.NITROGEN.name(), createPlanComplete(DataType.NITROGEN, completeInfo.getPlanNitrogen(), completeInfo.getNitrogen(), 0, RoundingMode.CEILING));
        result.put(DataType.GASEXT.name(), createPlanComplete(DataType.GASEXT, completeInfo.getPlanGasext(), completeInfo.getGasext(), 0, RoundingMode.CEILING));
        result.put(DataType.MATERIAL.name(), createPlanComplete(DataType.MATERIAL, completeInfo.getPlanMaterial(), completeInfo.getMaterial(), 0, RoundingMode.CEILING));
        result.put(DataType.RECYCLE.name(), createPlanComplete(DataType.RECYCLE, completeInfo.getPlanRecycle(), completeInfo.getRecycle(), 0, RoundingMode.CEILING));

        //水电
        DynamicDataSourceContextHolder.push("energy");
        MonthValue waterAndElectricity = statisticMapper.costWaterAndElectricity(dateRange[0], dateRange[1],keywordStr);
        DynamicDataSourceContextHolder.clear();
        waterAndElectricity = waterAndElectricity == null ? new MonthValue() : waterAndElectricity;


        PlanOtherStatisticVO planOtherStatisticVO = statisticMapper.planOtherPower(dateRange[0], dateRange[1], keywordStr);
        waterAndElectricity.setTotal2(planOtherStatisticVO!=null?planOtherStatisticVO.getPower().multiply(new BigDecimal("10000")):new BigDecimal("0"));

        PlanStatisticVO water = new PlanStatisticVO();
        water.setDataCode(DataType.WATER.name());
        water.setDataName(DataType.WATER.getDesc());
        water.setPlanTotal(completeInfo.getPlanWater().setScale(0,RoundingMode.HALF_UP));//计划
        water.setCompleteTotal(completeInfo.getWater().setScale(2,RoundingMode.HALF_UP));//执行
        water.setPercent(water.getPlanTotal().compareTo(BigDecimal.ZERO) == 0 ? Constants.ZERO : water.getCompleteTotal().multiply(Constants.HUNDRED).divide(water.getPlanTotal(), 0, RoundingMode.CEILING));
        result.put(DataType.WATER.name(), water);

        PlanStatisticVO power = new PlanStatisticVO();
        power.setDataCode(DataType.POWER.name());
        power.setDataName(DataType.POWER.getDesc());
        power.setPlanTotal(completeInfo.getPlanPower().setScale(0, RoundingMode.CEILING));
        power.setCompleteTotal(waterAndElectricity.getTotal2().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING));
        power.setPercent(power.getPlanTotal().compareTo(BigDecimal.ZERO) == 0 ? Constants.ZERO : power.getCompleteTotal().multiply(Constants.HUNDRED).divide(power.getPlanTotal(), 0, RoundingMode.CEILING));
        result.put(DataType.POWER.name(), power);
        return result;
    }

    @Override
    public ExecutionInfoVO otherActualByCompanyCodeOrMineCodeOrName(Integer month, String companyCode,String companyName, String mineCode) {
        Map<String, String> map = new HashMap<>();
        if(companyCode!=null&&!companyCode.equals("")&&(mineCode==null||mineCode=="")){
            map = MineInfo.getNameByCompanyCodeOfMap(companyCode);
        }else{
            map = MineInfo.getNameByMineCodeAndName(companyCode,companyName,mineCode,null);
        }

        StringBuffer value = new StringBuffer();
        for(String key : map.keySet()){
            value.append(key).append(",");
            //根据矿编码汇总数据
        }
        String keywordStr = value.deleteCharAt(value.length() - 1).toString();//去掉最后一个逗号
        map.clear();




        Date[] dateRange = DateUtils.getDateRange(null,month);
        ExecutionInfoVO vo = new ExecutionInfoVO();

        DynamicDataSourceContextHolder.push("shipped");
        List<MonthValue> sales = statisticMapper.realSaleOfMonth(dateRange[0], dateRange[1],keywordStr);
        DynamicDataSourceContextHolder.clear();

        vo.setSaleRevenue(BigDecimal.valueOf(sales.stream().mapToDouble(o -> o.getTotal2().doubleValue()).sum()).divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING));
        vo.setRevenue(vo.getSaleRevenue().add(vo.getPackageRevenue()).add(vo.getSubRoadRevenue()));

        //水电
        DynamicDataSourceContextHolder.push("energy");
        MonthValue waterAndElectricity = statisticMapper.costWaterAndElectricity(dateRange[0], dateRange[1],keywordStr);
        DynamicDataSourceContextHolder.clear();
        waterAndElectricity = waterAndElectricity == null ? new MonthValue() : waterAndElectricity;
//        vo.setOtherCost(result.get(0));
//        vo.setOilCost(result.get(1));
//        vo.setGasCost(result.get(2));
        vo.setWaterCost(waterAndElectricity.getTotal().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING));
        vo.setPowerCost(waterAndElectricity.getTotal2().divide(Constants.TEN_THOUSAND, 2, RoundingMode.CEILING));

        vo.setCost(vo.getOtherCost().add(vo.getOilCost()).add(vo.getGasCost()).add(vo.getWaterCost()).add(vo.getPowerCost()));

        return vo;
    }

    /**
     * 构建对象
     *
     * @param dataType 计划类型
     * @param plan     计划量
     * @param complete 完成量
     * @return 数据统计结果
     */
    private PlanStatisticVO createPlanComplete(DataType dataType, BigDecimal plan, BigDecimal complete, int scale, RoundingMode mode) {
        PlanStatisticVO vo = new PlanStatisticVO();
        vo.setDataCode(dataType.name());
        vo.setDataName(dataType.getDesc());
        vo.setPlanTotal(plan.setScale(scale, mode));
        vo.setCompleteTotal(complete.setScale(scale, mode));
        vo.setPercent(vo.getPlanTotal().compareTo(BigDecimal.ZERO) == 0 ? Constants.ZERO : vo.getCompleteTotal().multiply(Constants.HUNDRED).divide(vo.getPlanTotal(), scale, mode));
        return vo;
    }

    private PlanStatisticVO createPlanComplete(DataType dataType, BigDecimal plan, BigDecimal complete) {
        return createPlanComplete(dataType, plan, complete, 2, RoundingMode.CEILING);
    }

    public static Integer getWeekOfMonth(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        //外国月份为0-11所以月份加一
        int month = cal.get(Calendar.MONTH)+1;
        int mweek = cal.get(Calendar.WEEK_OF_MONTH);
        //String d = +"第"+mweek+"周";
        return mweek;
    }
}
